#include <sys_config.h>
#include <types.h>
#include <basic_types.h>
#include <mediatypes.h>
#include <api/libc/printf.h>
#include <api/libc/string.h>
#include <osal/osal.h>
#include <api/libpub/lib_frontend.h>
#include <hld/decv/decv.h>
#include <api/libosd/osd_lib.h>
#include <api/libtsi/psi_db.h>
#include <bus/tsi/tsi.h>

#include "osdobjs_def.h"
#include "string.id"
#include "images.id"
#include "osd_config.h"
#include "menus_root.h"
#include "win_com.h"
#include "win_com_popup.h"
#include "win_com_list.h"
#include "win_signalstatus.h"
#include <api/libpub/as_module.h>//Martin@20150410_ScanFrq


#define DBG_PRINTF PRINTF//soc_printf

//vicky130306#4
#if defined(SUPPORT_VMX_STD) || defined(SUPPORT_VMX)
#if 0
#define VMX_API_PRINTF		libc_printf
#else
#define VMX_API_PRINTF(...)	do{}while(0)
#endif
#endif
/*******************************************************************************
*	Objects definition
*******************************************************************************/
extern CONTAINER    g_win_search;
#if Maker_GUI_ON
extern TEXT_FIELD   srch_title_back;
#endif
extern TEXT_FIELD   srch_tv_back;
extern TEXT_FIELD   srch_radio_back;
extern TEXT_FIELD   srch_tp_back;
extern TEXT_FIELD   srch_line_h;
extern TEXT_FIELD   srch_line_v;
extern TEXT_FIELD   srch_info;
extern PROGRESS_BAR srch_progress_bar;
extern TEXT_FIELD   srch_progress_txt;
extern BITMAP       srch_bmp;
extern CONTAINER    srch_info_ex;
extern TEXT_FIELD   srch_info_txt_ex;
extern TEXT_FIELD   srch_info_line;
//Martin@20150410_ScanFrq
extern TEXT_FIELD   srch_freq_txt;
extern TEXT_FIELD   srch_bw_txt;
extern TEXT_FIELD   srch_freq_value;
extern TEXT_FIELD   srch_bw_value;


#define WIN_SH_IDX	                    WSTL_WINSEARCH
#define WIN_HL_IDX	                    WIN_SH_IDX
#define WIN_SL_IDX	                    WIN_SH_IDX
#define WIN_GRY_IDX                     WIN_SH_IDX

#define TVBACK_SH_IDX		            WSTL_TEXT_09_HD
#define RADIOBACK_SH_IDX	            WSTL_TEXT_09_HD
#define TPBACK_SH_IDX		            WSTL_TEXT_09_HD

#define BMP_SH_IDX			            WSTL_TEXT_08_HD//sharon WSTL_MIX_BMP_HD //WSTL_TEXT_08
#define TV_TXT_SH_IDX		            WSTL_TEXT_09_HD
#define RADIO_TXT_SH_IDX	            WSTL_TEXT_09_HD
#define TP_TXT_SH_IDX		            WSTL_TEXT_08_HD
#define PROGRESS_TXT_SH_IDX	            WSTL_TEXT_10_HD

#define PROGRESSBAR_SH_IDX			    WSTL_BARBG_01_HD
#define PROGRESSBAR_MID_SH_IDX		    WSTL_NOSHOW_IDX
#define PROGRESSBAR_PROGRESS_SH_IDX	    WSTL_BAR_04_HD//WSTL_BAR_04

#define INFOMATION_TXT_IDX              WSTL_BUTTON_01_HD
#define WIN_CON_NOSHOW                  WSTL_NOSHOW_IDX

#ifndef SD_UI
#if Maker_GUI_OFF
#define	W_L     	Maker_GUI_SM_L//210//206//17
#define	W_T     	Maker_GUI_MM_T//138//114//60
#define TEMP_W_T	W_T + 60
#ifdef SUPPORT_CAS_A
#define	W_W	886
#else
#define	W_W	Maker_GUI_SM_W
#endif
#define	W_H     	Maker_GUI_Frame_H//320
#define TEMP_W_H	W_H - 95
#else
#define	W_L     	74//210//206//17
#define	W_T     	98//138//114//60
#ifdef SUPPORT_CAS_A
#define	W_W	886
#else
#define	W_W	866
#endif
#define	W_H     	488//320
#endif

#define TVR_OFFSET	30
#define TVB_L		(W_L+TVR_OFFSET)
#if Maker_GUI_OFF
#define TVB_T 	TEMP_W_T
#else
#define TVB_T		(W_T)
#endif
#define TVB_W		(W_W/2-TVR_OFFSET)
#if Maker_GUI_OFF
#define TVB_H		(TEMP_W_H/2 - 4)
#else
#define TVB_H		(W_H/2 - 4)
#endif

#define RADIOB_L		(TVB_L + TVB_W)
#if Maker_GUI_OFF
#define RADIOB_T		TEMP_W_T
#else
#define RADIOB_T		(W_T)
#endif
#define RADIOB_W		(W_W/2-TVR_OFFSET)
#define RADIOB_H		TVB_H

#define SEARCH_LINEV_L		(TVB_L+TVB_W)
#define SEARCH_LINEV_T		(TVB_T)
#define SEARCH_LINEV_W		2
#define SEARCH_LINEV_H		(TVB_H-18)

#define SEARCH_LINEH_L		(W_L+20)
#define SEARCH_LINEH_T		(TVB_T + TVB_H)
#define SEARCH_LINEH_W		(W_W-40)
#define SEARCH_LINEH_H		2

#define TPB_L		(W_L+TVR_OFFSET)
#define TPB_T		(TVB_T + TVB_H)
#define TPB_W		(W_W-TVR_OFFSET*2)
#if Maker_GUI_OFF
#define TPB_H		(TEMP_W_H - TVB_H - TVR_OFFSET)
#else
#define TPB_H		(W_H - TVB_H - TVR_OFFSET)
#endif

#define BAR_L	(W_L+4)
#if Maker_GUI_ON
#define BAR_T	(W_T + W_H + 20)
#else
#define BAR_T	(W_T + W_H + 10)
#endif
#define BAR_W	(W_W - BAR_TXT_W - 10)
#define BAR_H	24//216

#define BAR_TXT_L (BAR_L + BAR_W + 2)
#define BAR_TXT_W	80//sharon 60
#define BAR_TXT_T ( BAR_T - 6)
#define BAR_TXT_H	36//24 

#define INFO_TXT_H	40//36//24

#define INFO_TV_T	(TVB_T + 30)
#define INFO_TV_L	(TVB_L + 30)
#define INFO_TV_W	(TVB_W - 50)

#define INFO_RADIO_T	(RADIOB_T + 30)
#define INFO_RADIO_L	(RADIOB_L + 30)
#define INFO_RADIO_W	(RADIOB_W - 50)

#define INFO_TP_T		(TPB_T + 16)
#define INFO_TP_L		(TPB_L + 20) //(TPB_L + 6)
#define INFO_TP_W		(TPB_W - 200)

#define INFO_SAT_L		725//sharon 745//881//463
#define INFO_SAT_T		350//sharon 340//380//220
#define INFO_SAT_W		195//130
#define INFO_SAT_H		60//40

#define INFO_RCV_L		724//860//464
#define INFO_RCV_T		486//536//430//370//330
#define INFO_RCV_W		78//50
#define INFO_RCV_H		74//50

#define INFO_WAV_L		755//sharon 726//862//464
#define INFO_WAV_T		410//sharon 402//442//510//264
#define INFO_WAV_W		70//sharon 88//50
#define INFO_WAV_H		70//sharon 96//58

#define INFOR_CHAN_CNT		5
#define INFOR_TP_CNT		5

#define TXT_L_OF     20//5
#define TXT_T_OF     0
#define TXT_W        (INFO_TV_W - 8)//(TVB_W - 8) 
#define TXT_H        36

#define LINE_L_OF    0 
#define LINE_T_OF    TXT_H
#define LINE_W       INFO_TV_W//()TVB_W 
#define LINE_H       2   
#else
#define	W_L     	17//210//206//17
#define	W_T     	57//138//114//60
#define	W_W			570//576
#define	W_H     	370//320

#define TVR_OFFSET	10
#define TVB_L		(W_L+TVR_OFFSET)
#define TVB_T		(W_T)
#define TVB_W		(W_W/2-TVR_OFFSET)
#define TVB_H		(W_H/2)

#define RADIOB_L		(TVB_L + TVB_W)
#define RADIOB_T		(W_T)
#define RADIOB_W		(W_W/2-TVR_OFFSET)
#define RADIOB_H		TVB_H

#define SEARCH_LINEV_L		(TVB_L+TVB_W)
#define SEARCH_LINEV_T		(TVB_T+8)
#define SEARCH_LINEV_W		2
#define SEARCH_LINEV_H		(TVB_H-18)

#define SEARCH_LINEH_L		(W_L+20)
#define SEARCH_LINEH_T		(TVB_T + TVB_H)
#define SEARCH_LINEH_W		(W_W-40)
#define SEARCH_LINEH_H		2

#define TPB_L		(W_L+TVR_OFFSET)
#define TPB_T		(TVB_T + TVB_H)
#define TPB_W		(W_W-TVR_OFFSET*2)
#define TPB_H		(W_H - TVB_H - TVR_OFFSET)

#define BAR_L	(W_L+4)
#define BAR_T	(W_T + W_H + 10)
#define BAR_W	(W_W - BAR_TXT_W - 10)
#define BAR_H	16//24//216

#define BAR_TXT_L (BAR_L + BAR_W + 2)
#define BAR_TXT_W	60//sharon 60
#define BAR_TXT_T ( BAR_T - 6)
#define BAR_TXT_H	24//24 

#define INFO_TXT_H	28//36//24

#define INFO_TV_T	(TVB_T + 30)
#define INFO_TV_L	(TVB_L + 30)
#define INFO_TV_W	(TVB_W - 50)

#define INFO_RADIO_T	(RADIOB_T + 30)
#define INFO_RADIO_L	(RADIOB_L + 30)
#define INFO_RADIO_W	(RADIOB_W - 50)

#define INFO_TP_T		(TPB_T + 16)
#define INFO_TP_L		(TPB_L + 10) //(TPB_L + 6)
#define INFO_TP_W		(TPB_W - 200)

#define INFO_SAT_L		420//sharon 745//881//463
#define INFO_SAT_T		242//sharon 340//380//220
#define INFO_SAT_W		130//130
#define INFO_SAT_H		40//40

#define INFO_RCV_L		420//860//464
#define INFO_RCV_T		340//536//430//370//330
#define INFO_RCV_W		50//50
#define INFO_RCV_H		50//50

#define INFO_WAV_L		420//sharon 726//862//464
#define INFO_WAV_T		280//sharon 402//442//510//264
#define INFO_WAV_W		60//sharon 88//50
#define INFO_WAV_H		60//sharon 96//58

#define INFOR_CHAN_CNT		5
#define INFOR_TP_CNT		5

#define TXT_L_OF     20//5
#define TXT_T_OF     0
#define TXT_W        (INFO_TV_W - 8)//(TVB_W - 8) 
#define TXT_H        36

#define LINE_L_OF    0 
#define LINE_T_OF    TXT_H
#define LINE_W       INFO_TV_W//()TVB_W 
#define LINE_H       2   

#endif
static PRESULT srch_backtxt_callback(POBJECT_HEAD pObj, VEVENT event, UINT32 param1, UINT32 param2);
static PRESULT srch_callback(POBJECT_HEAD pObj, VEVENT event, UINT32 param1, UINT32 param2);
static VACTION srch_keymap(POBJECT_HEAD pObj, UINT32 key);

#if Maker_GUI_ON
#ifndef SD_UI
#if Maker_GUI_ON
#define TITLE_L	Maker_GUI_SM_L//210
#define TITLE_T Maker_GUI_MM_T//70
#ifdef SUPPORT_CAS_A
#define TITLE_W 886
#else
#define TITLE_W Maker_GUI_SM_W
#endif
#define TITLE_H 60
#else
#define TITLE_L	74//210
#define TITLE_T 30//70
#ifdef SUPPORT_CAS_A
#define TITLE_W 886
#else
#define TITLE_W 866
#endif
#define TITLE_H 68
#endif
#else
#define TITLE_L 17//210
#define TITLE_T 17//70
#define TITLE_W 570
#define TITLE_H 40
#endif

#define TITLE_SH_IDX	WSTL_WIN_TITLE_YJ	//WSTL_WIN_TITLE_01_HD

/*
DEF_TEXTFIELD(menu_title_txt,NULL,NULL,C_ATTR_ACTIVE,0, \
              0,0,0,0,0, TITLE_L,TITLE_T,TITLE_W,TITLE_H, TITLE_SH_IDX,TITLE_SH_IDX,TITLE_SH_IDX,TITLE_SH_IDX,   \
              NULL,NULL,  \
              C_ALIGN_CENTER | C_ALIGN_TOP, 0,8,0,NULL)
*/
#define LDEF_BACK_AOV(root,varTxt,nxtObj,resID)		\
DEF_TEXTFIELD(varTxt,root,nxtObj,C_ATTR_ACTIVE,0, \
          0,0,0,0,0, TITLE_L,TITLE_T,TITLE_W,TITLE_H, TITLE_SH_IDX,TITLE_SH_IDX,TITLE_SH_IDX,TITLE_SH_IDX,   \
          NULL,NULL,  \
          C_ALIGN_CENTER | C_ALIGN_TOP, 0,8,resID,NULL)
#endif

#define LDEF_BACK(root,varTxt,nxtObj,id,sh,l,t,w,h,resID)		\
    DEF_TEXTFIELD(varTxt,root,nxtObj,C_ATTR_ACTIVE,0, \
    id,id,id,id,id, l,t,w,h, sh,sh,sh,sh,   \
    NULL,srch_backtxt_callback,  \
    C_ALIGN_LEFT| C_ALIGN_TOP,56,4,resID,NULL)

#define LDEF_SEARCH_LINE(parent, varTxt, nxtObj, l, t, w, h, str)		\
    DEF_TEXTFIELD(varTxt,parent,nxtObj,C_ATTR_ACTIVE,0, \
    0, 0, 0, 0, 0, l, t, w, h, WSTL_LINE_MENU_HD,WSTL_LINE_MENU_HD,WSTL_LINE_MENU_HD,WSTL_LINE_MENU_HD,   \
    NULL,NULL,  \
    C_ALIGN_CENTER | C_ALIGN_VCENTER, 0,0,0,str)

#define LDEF_INFOR_TXT(root,varTxt)		\
    DEF_TEXTFIELD(varTxt,root,NULL,C_ATTR_ACTIVE,0, \
    0,0,0,0,0,  0,0,0,0, 0,0,0,0,   \
    NULL,NULL,  \
    C_ALIGN_LEFT | C_ALIGN_VCENTER, 0,0,0,display_strs[0])


#define LDEF_INFOR_BMP(root,varBmp)		\
  DEF_BITMAP(varBmp,root,NULL,C_ATTR_ACTIVE,0, \
    0,0,0,0,0, 0,0,0,0, BMP_SH_IDX,BMP_SH_IDX,BMP_SH_IDX,BMP_SH_IDX,   \
    NULL,NULL,  \
    C_ALIGN_LEFT | C_ALIGN_VCENTER, 0,0,0)


#if Maker_GUI_OFF
#define LDEF_PROGRESS_BAR(root,varBar,nxtObj,l,t,w,h,style,rl,rt,rw,rh)    \
   DEF_PROGRESSBAR(varBar, root, nxtObj, C_ATTR_ACTIVE, 0, \
	   0, 0, 0, 0, 0, l, t, w, h, PROGRESSBAR_SH_IDX, PROGRESSBAR_SH_IDX, PROGRESSBAR_SH_IDX, PROGRESSBAR_SH_IDX,\
	   NULL, NULL, style, 0, 0, PROGRESSBAR_MID_SH_IDX, PROGRESSBAR_PROGRESS_SH_IDX, \
	   rl,rt , rw, rh, 1, 100, 50, 1)
#else
 #define LDEF_PROGRESS_BAR(root,varBar,nxtObj,l,t,w,h,style,rl,rt,rw,rh)	\
	DEF_PROGRESSBAR(varBar, root, nxtObj, C_ATTR_ACTIVE, 0, \
		0, 0, 0, 0, 0, l, t, w, h, PROGRESSBAR_SH_IDX, PROGRESSBAR_SH_IDX, PROGRESSBAR_SH_IDX, PROGRESSBAR_SH_IDX,\
		NULL, NULL, style, 0, 0, PROGRESSBAR_MID_SH_IDX, PROGRESSBAR_PROGRESS_SH_IDX, \
		rl,rt , rw, rh, 1, 100, 100, 1)
#endif
   
#define LDEF_PROGRESS_TXT(root,varTxt,nxtObj,l,t,w,h)		\
    DEF_TEXTFIELD(varTxt,root,NULL,C_ATTR_ACTIVE,0, \
    0,0,0,0,0, l,t,w,h, PROGRESS_TXT_SH_IDX,PROGRESS_TXT_SH_IDX,PROGRESS_TXT_SH_IDX,PROGRESS_TXT_SH_IDX,   \
    NULL,NULL,  \
    C_ALIGN_RIGHT| C_ALIGN_VCENTER, 0,0,0,display_strs[1])

#define LDEF_TXT(root,varTxt,nxtObj,l,t,w,h)		\
    DEF_TEXTFIELD(varTxt,root,nxtObj,C_ATTR_ACTIVE,0, \
    0,0,0,0,0, l,t,w,h,TV_TXT_SH_IDX,TV_TXT_SH_IDX,TV_TXT_SH_IDX,TV_TXT_SH_IDX,   \
    NULL,NULL,  \
    C_ALIGN_LEFT | C_ALIGN_VCENTER, 0,0,0,display_strs[3])

#define LDEF_CON(root, varCon,nxtObj,ID,IDl,IDr,IDu,IDd,l,t,w,h,conobj,focusID)		\
    DEF_CONTAINER(varCon,root,nxtObj,C_ATTR_ACTIVE,0, \
    ID,IDl,IDr,IDu,IDd, l,t,w,h, WIN_CON_NOSHOW,WIN_CON_NOSHOW,WIN_CON_NOSHOW,WIN_CON_NOSHOW,   \
    NULL,NULL,  \
    conobj, ID,1)

#undef LDEF_LINE
#define LDEF_LINE(root,varTxt,nxtObj,ID,IDl,IDr,IDu,IDd,l,t,w,h,resID,str)		\
    DEF_TEXTFIELD(varTxt,root,nxtObj,C_ATTR_ACTIVE,0, \
    ID,IDl,IDr,IDu,IDd, l,t,w,h, WSTL_LINE_MENU_HD,WSTL_LINE_MENU_HD,WSTL_LINE_MENU_HD,WSTL_LINE_MENU_HD,   \
    NULL,NULL,  \
    C_ALIGN_RIGHT | C_ALIGN_VCENTER, 10,0,resID,str)



#define LDEF_MENU_ITEM_TXT(root,varCon,nxtObj,varTxt,varLine,ID,IDu,IDd,\
						l,t,w,h) \
    LDEF_CON(root,varCon,nxtObj,ID,ID,ID,IDu,IDd,l,t,w,h,&varTxt,ID)   \
    LDEF_TXT(&varCon,varTxt,NULL/*&varLine*/,l + TXT_L_OF,t + TXT_T_OF,TXT_W,TXT_H )\
	LDEF_LINE(&varCon,varLine,NULL,1,1,1,1,1,l + LINE_L_OF, t + LINE_T_OF,LINE_W,LINE_H,0,0)


#define LDEF_WIN(varCon,nxtObj,l,t,w,h,focusID)		\
    DEF_CONTAINER(varCon,NULL,NULL,C_ATTR_ACTIVE,0, \
    0,0,0,0,0, l,t,w,h, WIN_SH_IDX,WIN_HL_IDX,WIN_SL_IDX,WIN_GRY_IDX,   \
    srch_keymap,srch_callback,  \
    nxtObj, focusID,0)

//Martin@20150410_ScanFrq ---------------
#define ScanFrq_ID		4
#define ScanBw_ID		5

#define AOV_OFFSET 10
#define AOV_FREQ_TXT__L W_L
#define AOV_FREQ_TXT__T 561
#define AOV_FREQ_TXT__W 250
#define AOV_FREQ_TXT__H 35

#define AOV_BW_TXT__L RADIOB_L
#define AOV_BW_TXT__T 561
#define AOV_BW_TXT__W 250
#define AOV_BW_TXT__H 35

#define AOV_FREQ_VALUE__L (AOV_FREQ_TXT__L + AOV_FREQ_TXT__W - 70)
#define AOV_FREQ_VALUE__T AOV_FREQ_TXT__T+2
#define AOV_FREQ_VALUE__W 200
#define AOV_FREQ_VALUE__H 35

#define AOV_BW_VALUE__L (AOV_BW_TXT__L + AOV_BW_TXT__W - 70)
#define AOV_BW_VALUE__T AOV_BW_TXT__T+2
#define AOV_BW_VALUE__W 200
#define AOV_BW_VALUE__H 35
//---------------------------------


#define TVB_ID		1
#define RADIOB_ID	2
#define TPB_ID		3

#if Maker_GUI_ON
LDEF_BACK_AOV(&g_win_search,srch_title_back,&srch_tv_back,RS_INSTALLATION_AUTO_SCAN)
#endif

LDEF_BACK(&g_win_search,srch_tv_back,&srch_radio_back,	TVB_ID ,TVBACK_SH_IDX,\
		TVB_L, TVB_T, TVB_W, TVB_H, RS_INFO_TV)

LDEF_BACK(&g_win_search,srch_radio_back,&srch_tp_back,	RADIOB_ID, RADIOBACK_SH_IDX,\
		RADIOB_L, RADIOB_T, RADIOB_W, RADIOB_H, RS_INFO_RADIO)

LDEF_BACK(&g_win_search,srch_tp_back,&srch_line_v, TPB_ID,TPBACK_SH_IDX,\
		TPB_L, TPB_T, TPB_W, TPB_H, 0)

LDEF_SEARCH_LINE(&g_win_search, srch_line_v, &srch_line_h, \
		SEARCH_LINEV_L, SEARCH_LINEV_T, SEARCH_LINEV_W, SEARCH_LINEV_H, NULL)
LDEF_SEARCH_LINE(&g_win_search, srch_line_h, &srch_freq_txt, \
		SEARCH_LINEH_L, SEARCH_LINEH_T, SEARCH_LINEH_W, SEARCH_LINEH_H, NULL)
#ifndef SD_UI
/*Martin@20150115_progress_bar*/
//LDEF_PROGRESS_BAR(&g_win_search,srch_progress_bar,&srch_progress_txt,	\
		BAR_L, BAR_T, BAR_W, BAR_H, PROGRESSBAR_HORI_NORMAL | PBAR_STYLE_RECT_STYLE,2,5,BAR_W - 4,BAR_H - 10)

//Martin@20150410_ScanFrq -
LDEF_BACK(&g_win_search, srch_freq_txt, &srch_freq_value, ScanFrq_ID, TVBACK_SH_IDX,\
				AOV_FREQ_TXT__L, AOV_FREQ_TXT__T, AOV_FREQ_TXT__W, AOV_FREQ_TXT__H, RS_DISPLAY_FREQUENCY)

LDEF_TXT(&g_win_search,srch_freq_value,&srch_bw_txt,AOV_FREQ_VALUE__L, AOV_FREQ_VALUE__T, AOV_FREQ_VALUE__W, AOV_FREQ_VALUE__H)

LDEF_BACK(&g_win_search, srch_bw_txt, &srch_bw_value, ScanBw_ID, TVBACK_SH_IDX,\
				AOV_BW_TXT__L, AOV_BW_TXT__T, AOV_BW_TXT__W, AOV_BW_TXT__H, RS_INSTALLATION_BANDWIDTH)

LDEF_TXT(&g_win_search, srch_bw_value, &srch_progress_bar, AOV_BW_VALUE__L, AOV_BW_VALUE__T, AOV_BW_VALUE__W, AOV_BW_VALUE__H)
//End Martin---------------
LDEF_PROGRESS_BAR(&g_win_search,srch_progress_bar,&srch_progress_txt,	\
				BAR_L, BAR_T, BAR_W, BAR_H, PROGRESSBAR_HORI_NORMAL | PBAR_STYLE_RECT_STYLE,6,5,BAR_W -12 ,BAR_H - 10)
#else
LDEF_PROGRESS_BAR(&g_win_search,srch_progress_bar,&srch_progress_txt,	\
		BAR_L, BAR_T, BAR_W, BAR_H, PROGRESSBAR_HORI_NORMAL | PBAR_STYLE_RECT_STYLE,2,2,BAR_W -3 ,BAR_H - 4)
#endif

LDEF_PROGRESS_TXT(&g_win_search, srch_progress_txt, NULL, \
		BAR_TXT_L, BAR_TXT_T, BAR_TXT_W, BAR_TXT_H)


LDEF_INFOR_TXT(&g_win_search,srch_info)
LDEF_INFOR_BMP(&g_win_search,srch_bmp)

LDEF_MENU_ITEM_TXT(NULL, srch_info_ex, NULL, srch_info_txt_ex, srch_info_line, 0, 0, 0,\
                   0,0,0,0)

#if Maker_GUI_ON
LDEF_WIN(g_win_search,&srch_title_back,W_L, W_T-60, W_W, W_H+60,1)
#else
LDEF_WIN(g_win_search,&srch_tv_back,W_L, W_T, W_W, W_H,1)
#endif

//---------------------------------------------------------------------------------------------------------------------

UINT16 srch_wave_ids[] =
{
	IM_SATELLITE_LINE_1,
	IM_SATELLITE_LINE_2,
	IM_SATELLITE_LINE_3,
	IM_SATELLITE_LINE_4,
	IM_SATELLITE_LINE_5,
};
#define SRCH_WAVE_ICON_CNT (sizeof(srch_wave_ids)/sizeof(srch_wave_ids[0]))
static struct as_service_param win_search_param;
static BOOL  SearchComplete = FALSE;
static BOOL AutoScanMunalUpdate = FALSE;

static UINT32 srch_first_prog_id[2];//ChengYu@20130927, play the first program after scan

void SetAutoScanUpdateMode(BOOL mode) /// 0: reinstall mode, 1: update mode,
{
	AutoScanMunalUpdate = mode;
}

BOOL AutoScanUpdateMode()
{
	return AutoScanMunalUpdate;
}

#ifndef SD_UI
static UINT16 dvbs_tp_info_w_tbl[] =
{
	60,//40,
	240,//164,
	100,//60,
	30,//20,
	90,//60,
	30,//20,
	60,//60
};
static UINT8 dvbs_tp_info_chw_tbl[] = 
{
	5, 		/* index */
	18,		/* name  */
	6,		/* freq  */
	2,		/* h/v  */
	6,		/* symb  */
};
static UINT16 dvbc_tp_info_w_tbl[] =
{
	40,
	90+140,//60,
	90+50,//60,
	120, //30,//20,
	30,//20,
	60,//120,//60
};
static UINT8 dvbc_tp_info_chw_tbl[] =
{
	4,//5, 		/* index */
	6+10,		/* freq  */
	6+4,		/* symb  */
	7,          /* QAM */
};
#else
static UINT16 dvbs_tp_info_w_tbl[] =
{
	40,//40,
	140,//164,
	60,//60,
	20,//20,
	60,//60,
	20,//20,
	40,//60
};
static UINT8 dvbs_tp_info_chw_tbl[] = 
{
	5, 		/* index */
	18,		/* name  */
	6,		/* freq  */
	2,		/* h/v  */
	6,		/* symb  */
};
static UINT16 dvbc_tp_info_w_tbl[] =
{
	30,
	110,//60,
	60,//60,
	90, //30,//20,
	30,//20,
	40,//120,//60
};
static UINT8 dvbc_tp_info_chw_tbl[] =
{
	4,//5, 		/* index */
	6+10,		/* freq  */
	6+4,		/* symb  */
	8,          /* QAM */
};
#endif

typedef struct
{
    struct as_service_param search_param;
    //sat
    BOOL   moving_disk;  
    UINT16 cur_searching_sat_no;
    UINT16 pre_sat_id;
    UINT16 cur_sat_id;

    //tp
    BOOL   cur_tp_srched_ok;
    UINT16 searched_tp_cnt;

    //prog
    UINT16 searched_channel_cnt[2];  //tv, radio
    P_NODE cur_searched_prog[2];
    
    //animation
    UINT32 animation_timer_loop;

    //pid search param
    BOOL pid_srch_flag;
    UINT32 pid_srch_v;
    UINT32 pid_srch_a;
    UINT32 pid_srch_p;
    UINT32 pid_srch_tp;    
    
    BOOL search_stop_signal;
    BOOL pre_close_signal;
    BOOL power_off_signal;
    
    
}WinSrchPriv;
extern UINT8 g_enter_welcom;//modify for adding welcome page when only open dvbt 2011 10 18

extern struct as_module_info *as_info;


static WinSrchPriv* priv = NULL; 
//modify for channel scan mode show the title auto scan on T tuner 2011 11 25
BOOL is_auto_scan=TRUE;
static UINT16 get_sat_pos(UINT16 sat_id)
{
    UINT32 i, j;
    UINT32 sat_cnt;
    S_NODE s_node;

    i = 0;
    while(i < get_tuner_cnt())
    {
        sat_cnt = get_tuner_sat_cnt(i);
        for(j=0; j<sat_cnt; j++)
        {
            get_tuner_sat(i, j, &s_node);
            if(sat_id == s_node.sat_id)
                return j;
        }
        i++;
    }
   // ASSERT(0);
    return 0;
}

static void win_srch_draw_bmp(OSD_RECT* pRect, UINT16 iconID)
{
	BITMAP* bmp;
	bmp = &srch_bmp;
	OSD_SetRect2(&bmp->head.frame,pRect);
	OSD_SetBitmapContent(bmp, iconID);
	OSD_DrawObject( (POBJECT_HEAD)bmp, C_UPDATE_ALL);
}

static void win_srch_draw_info(OSD_RECT* pRect, char* str, UINT16* unistr, UINT8 shidx)
{
	TEXT_FIELD* txt;
	txt = &srch_info;
	OSD_SetRect2(&txt->head.frame,pRect);
	if(str != NULL)
		OSD_SetTextFieldContent(txt, STRING_ANSI, (UINT32)str);
	else if (unistr != NULL)
		OSD_SetTextFieldContent(txt, STRING_UNICODE, (UINT32)unistr);
	OSD_SetColor(txt,shidx,shidx,shidx,shidx);
	OSD_DrawObject( (POBJECT_HEAD)txt, C_UPDATE_ALL);
}

static void win_srch_draw_info_ex(OSD_RECT* pRect, char* str, UINT16* unistr, UINT8 shidx)
{
	PCONTAINER  pObj;
    TEXT_FIELD  *pTxt,*pLine;
    OSD_RECT     rect_01,rect_02;
    
    rect_01.uTop = pRect->uTop+TXT_T_OF;
    rect_01.uLeft = pRect->uLeft+TXT_L_OF;
    rect_01.uWidth = TXT_W;
    rect_01.uHeight = TXT_H;

    rect_02.uTop =  pRect->uTop + LINE_T_OF;
    rect_02.uLeft=  pRect->uLeft+LINE_L_OF;
    rect_02.uHeight = LINE_H;
    rect_02.uWidth  = TXT_W;
    
	pObj = &srch_info_ex;//&srch_info;
	pTxt = &srch_info_txt_ex;
    pLine = &srch_info_line;
	//OSD_SetRect2(&pObj->head.frame,pRect);
	OSD_SetRect2(&pObj->head.frame,pRect);
	OSD_SetRect2(&pTxt->head.frame,&rect_01);
    OSD_SetRect2(&pLine->head.frame,&rect_02);
    //OSD_SetTextFieldContent() 
	if(str != NULL)
		OSD_SetTextFieldContent(pTxt, STRING_ANSI, (UINT32)str);
	else if (unistr != NULL)
		OSD_SetTextFieldContent(pTxt, STRING_UNICODE, (UINT32)unistr);
	//OSD_SetColor(pTxt,shidx,shidx,shidx,shidx);
	OSD_DrawObject( (POBJECT_HEAD)pObj, C_UPDATE_ALL);
}


static void win_search_program_append(UINT32 tp_idx, UINT16 prog_idx)
{
	UINT32 si,i,j,n,cnt,str_len;
	UINT16* pstr;
	OSD_RECT rect;
	UINT8	shidx;
	char    str[30];
	
	DBG_PRINTF("Enter %s....\n",__FUNCTION__);
	
	if(prog_idx != INVALID_ID)
	{
		P_NODE p_node;
#ifdef POLAND_SPEC_SUPPORT
		PostProcessing_GetProgNode(prog_idx, &p_node);
#else
		get_prog_at(prog_idx, &p_node);
#endif
		MEMCPY(&(priv->cur_searched_prog[p_node.av_flag]), &p_node, sizeof(p_node));
		
		priv->searched_channel_cnt[p_node.av_flag] ++;		
		cnt = priv->searched_channel_cnt[p_node.av_flag];

		//Martin@20150317_audio
#if 0//1//ChengYu@20130927, play the first program after scan
		if (cnt == 1)
		{
			srch_first_prog_id[p_node.av_flag] = priv->cur_searched_prog[p_node.av_flag].prog_id;
		}
#endif

		if(cnt <= INFOR_CHAN_CNT)
		{
			si = 0;
			n = cnt;
		}
		else
		{
			si = cnt - INFOR_CHAN_CNT;
			n = INFOR_CHAN_CNT;
		}

		if(si != 0)
		{
			for(i=0;i<n - 1;i++)
				MEMCPY(display_strs[10 + p_node.av_flag*10 + i], display_strs[10 + p_node.av_flag*10 + i + 1], MAX_DISP_STR_LEN*2);
		}

		pstr = display_strs[10 + p_node.av_flag*10 + n - 1];		
		if(p_node.ca_mode)
			ComAscStr2Uni("$", pstr);
		else
			ComAscStr2Uni("", pstr);
		str_len = ComUniStrLen(pstr);
		ComUniStrCopyChar((UINT8*)&pstr[str_len] ,p_node.service_name);

		if(p_node.av_flag == PROG_TV_MODE)
		{
			rect.uLeft 	= TVB_L + 20;//INFO_TV_L;
			rect.uTop  	= TVB_T + INFO_TXT_H;//INFO_TV_T+4;
			rect.uWidth = INFO_TV_W;
			rect.uHeight= INFO_TXT_H;
			shidx = TV_TXT_SH_IDX;
		}
		else
		{
			rect.uLeft 	= RADIOB_L + 20;//INFO_RADIO_L;
			rect.uTop  	= RADIOB_T + INFO_TXT_H;//INFO_RADIO_T+4;
			rect.uWidth = INFO_TV_W;//INFO_RADIO_W;
			rect.uHeight= INFO_TXT_H;
			shidx = RADIO_TXT_SH_IDX;
		}
		
		for(i=0;i<n;i++)
		{
			pstr = display_strs[10 + p_node.av_flag*10 + i];
			//win_srch_draw_info(&rect, NULL,pstr, shidx);
			win_srch_draw_info_ex(&rect, NULL,pstr, INFOMATION_TXT_IDX);
			rect.uTop += rect.uHeight;
		}

		#ifndef SD_UI
		rect.uTop = TVB_T;//INFO_TV_T - 24;
		rect.uLeft += (rect.uWidth-80);
		rect.uWidth = 80;
        rect.uHeight = TXT_H;
		#else
		rect.uTop = TVB_T;//INFO_TV_T - 24;
		rect.uLeft += (rect.uWidth-40);
		rect.uWidth = 60;
        rect.uHeight = TXT_H;
		#endif
		sprintf(str,"%d",cnt);
		win_srch_draw_info(&rect, str,NULL, shidx);
        priv->cur_tp_srched_ok = TRUE;		
	}
	if(tp_idx != 0xFFFFFFFF)
	{
		T_NODE t_node;
		S_NODE s_node;
        UINT8 *tp_info_chw_tbl;
        UINT16 *tp_info_w_tbl;
        UINT8 tp_info_chw_cnt;
        UINT8 tp_info_w_cnt;
        
        if(priv->search_param.as_frontend_type == FRONTEND_TYPE_C) 
        {
            tp_info_chw_tbl = dvbc_tp_info_chw_tbl;
            tp_info_w_tbl = dvbc_tp_info_w_tbl;
            tp_info_chw_cnt = ARRAY_SIZE(dvbc_tp_info_chw_tbl);
            tp_info_w_cnt = ARRAY_SIZE(dvbc_tp_info_w_tbl);
        }
        else
        {
            tp_info_chw_tbl = dvbs_tp_info_chw_tbl;
            tp_info_w_tbl = dvbs_tp_info_w_tbl;
            tp_info_chw_cnt = ARRAY_SIZE(dvbs_tp_info_chw_tbl);
            tp_info_w_cnt = ARRAY_SIZE(dvbs_tp_info_w_tbl);         
        }
        
    	if(tp_idx == 0) //show a TP finished status.
    	{
        	cnt = priv->searched_tp_cnt;
    		if(cnt <= INFOR_TP_CNT)
    		{
    			si = 0;
    			n = cnt;
    		}
    		else
    		{
    			si = cnt - INFOR_TP_CNT;
    			n = INFOR_TP_CNT;
    		}
            
			pstr = display_strs[ 30 + n - 1];
            str_len = 0;
            for(i=0; i< tp_info_chw_cnt; i++)
            {
                str_len += *(tp_info_chw_tbl+i);
            }
            if(priv->cur_tp_srched_ok)
				ComAscStr2Uni("OK", &pstr[str_len]);
			else
				ComAscStr2Uni("Failed", &pstr[str_len]);
    	}
        else    //(tp_idx != 0): append a new TP.
        {
    		get_tp_by_id(tp_idx, &t_node);
    		//get_sat_at(cur_sat_pos, VIEW_ALL,&s_node);
    		get_sat_by_id(priv->cur_sat_id, &s_node);
    		priv->searched_tp_cnt++;

        	cnt = priv->searched_tp_cnt;
    		if(cnt <= INFOR_TP_CNT)
    		{
    			si = 0;
    			n = cnt;
    		}
    		else
    		{
    			si = cnt - INFOR_TP_CNT;
    			n = INFOR_TP_CNT;
    		}
    		
    		if(si != 0) //Move up the shown TP list for append a TP at the end.
    		{
    			for(i=0;i<n - 1;i++)
    			{
    				MEMCPY(display_strs[ 30 + i], display_strs[30 + i + 1], MAX_DISP_STR_LEN*2);
    			}
    			MEMSET(display_strs[ 30 + i], 0, MAX_DISP_STR_LEN*2);   //clean up the last line.
    		}
    /*        
    		if(n>1) //show previous TP finished status.
    		{
    			pstr = display_strs[ 30 + n - 2];
                str_len = 0;
                for(i=0; i< tp_info_chw_cnt; i++)
                {
                    str_len += *(tp_info_chw_tbl+i);
                }
                if(priv->cur_tp_srched_ok)
    				ComAscStr2Uni("OK", &pstr[str_len]);
    			else
    				ComAscStr2Uni("Failed", &pstr[str_len]);
    		}
    */
		pstr = display_strs[30 + n - 1];		
		sprintf(str,"%d",priv->searched_tp_cnt);
		ComAscStr2Uni(str,&pstr[0]);
		str_len = *(tp_info_chw_tbl + 0);

        if(priv->search_param.as_frontend_type == FRONTEND_TYPE_C)
        {
        //for DVBC show frep when search
#ifdef  DVBC_SUPPORT
        get_freq_str(t_node.frq, (void *)(&pstr[str_len]), TRUE);
#else
        get_dvbc_freq_str(t_node.frq, (void *)(&pstr[str_len]), TRUE);
#endif
    		str_len += *(tp_info_chw_tbl + 1);
    		sprintf(str,"%d%s",t_node.sym, " KBps");
    		ComAscStr2Uni(str,&pstr[str_len]);
    		str_len += *(tp_info_chw_tbl + 2);
    		sprintf(str, "%s", QamTable[t_node.FEC_inner - 4]);
    		ComAscStr2Uni(str,&pstr[str_len]);
    		str_len += *(tp_info_chw_tbl + 3);
    		STRCPY(str,"");
    		ComAscStr2Uni(str,&pstr[str_len]);            
        }
        else if(priv->search_param.as_frontend_type == FRONTEND_TYPE_T)
        {
        		if (t_node.t2_signal)
        		{
            		sprintf(str,"%s","DVBT2");
            		ComAscStr2Uni(str,&pstr[str_len]);
        		}
                else
	    		ComUniStrCopyChar((UINT8*)&pstr[str_len], s_node.sat_name);   		
	    		str_len += *(tp_info_chw_tbl + 1);
	    		sprintf(str,"%d",t_node.frq);
	    		ComAscStr2Uni(str,&pstr[str_len]);
            
	    		str_len += *(tp_info_chw_tbl + 4);
    		STRCPY(str,"");
    		ComAscStr2Uni(str,&pstr[str_len]);            
        }
        else
        {
    		ComUniStrCopyChar((UINT8*)&pstr[str_len], s_node.sat_name);
   		
    		str_len += *(tp_info_chw_tbl + 1);
    		sprintf(str,"%d",t_node.frq);
    		ComAscStr2Uni(str,&pstr[str_len]);
    		
    		str_len += *(tp_info_chw_tbl + 2);
    		sprintf(str,"%c",(t_node.pol == 0)? 'H' : 'V');
    		ComAscStr2Uni(str,&pstr[str_len]);

    		str_len += *(tp_info_chw_tbl + 3);
    		sprintf(str,"%d",t_node.sym);
    		ComAscStr2Uni(str,&pstr[str_len]);

	    		str_len += *(tp_info_chw_tbl + 4);
	    		STRCPY(str,"");
	    		ComAscStr2Uni(str,&pstr[str_len]);
	        }
	        priv->cur_tp_srched_ok = FALSE;		
       	}
		
		rect.uLeft 	= INFO_TP_L;
		rect.uTop  	= INFO_TP_T;
		rect.uWidth = INFO_TP_W;
		rect.uHeight= INFO_TXT_H;
		shidx = TP_TXT_SH_IDX;
		for(i=0; i<n; i++)
		{			
			pstr = display_strs[30 + i];
#if 0			
			win_srch_draw_info(&rect, NULL,pstr, shidx);
#else
			rect.uLeft 	= INFO_TP_L;
			str_len = 0;
			pstr = display_strs[30 + i];
			for(j=0; j<tp_info_w_cnt; j++)
			{
				rect.uWidth = *(tp_info_w_tbl + j) - 2;	
				if(j != tp_info_chw_cnt)
					win_srch_draw_info(&rect, NULL,pstr, shidx);				
				else
				{
            //#if (SYS_PROJECT_FE == PROJECT_FE_DVBS || SYS_PROJECT_FE == PROJECT_FE_DVBS2)
                    win_srch_draw_info(&rect, "...",NULL, shidx);
           // #endif
				}
				rect.uLeft +=  *(tp_info_w_tbl + j);
				if(j < tp_info_chw_cnt)
				{
					pstr += *(tp_info_chw_tbl + j);
					//pstr += str_len;
				}
			}
#endif
			rect.uTop += rect.uHeight;
		}		
	}
	DBG_PRINTF("Exit %s....\n",__FUNCTION__);	
}



static void win_search_last_tp_ok_failed(UINT32 cnt)
{
	UINT8 i,j,n;
	UINT16 pstr[8];
	OSD_RECT rect;
    UINT16 *tp_info_w_tbl;
    UINT8 tp_info_w_cnt;
    
    if(priv->search_param.as_frontend_type == FRONTEND_TYPE_C) 
    {
        tp_info_w_tbl = dvbc_tp_info_w_tbl;
        tp_info_w_cnt = ARRAY_SIZE(dvbc_tp_info_w_tbl);
    }
    else
    {
        tp_info_w_tbl = dvbs_tp_info_w_tbl;
        tp_info_w_cnt = ARRAY_SIZE(dvbs_tp_info_w_tbl);         
    }

    if (cnt == 0)
        return;

	if(cnt <= INFOR_TP_CNT)
	{
		n = cnt;
	}
	else
	{
		n = INFOR_TP_CNT;
	}

	if(priv->cur_tp_srched_ok)
		ComAscStr2Uni("OK", pstr);
	else
		ComAscStr2Uni("Failed", pstr);

	rect.uLeft 	= INFO_TP_L;
	rect.uTop  	= INFO_TP_T;
	rect.uWidth = INFO_TP_W;
	rect.uHeight= INFO_TXT_H;

	//for(i=0;i<n;i++)
	{
		rect.uLeft 	= INFO_TP_L;
		if(n > 1)
			rect.uTop += rect.uHeight*(n -1);        
		for(j=0;j<tp_info_w_cnt;j++)
		{
			rect.uWidth = *(tp_info_w_tbl + j) - 2;
			if(j == tp_info_w_cnt-1)
				win_srch_draw_info(&rect, NULL,pstr, TP_TXT_SH_IDX);
			rect.uLeft += *(tp_info_w_tbl + j);
		}
		//rect.uTop += rect.uHeight;
	}
}


static PRESULT do_pid_search(void)
{
    INT32 ret = 0;
	UINT8 str[32];    
    P_NODE node;
	if(priv->pid_srch_flag)		
	{
		struct dmx_device *dmx = (struct dmx_device *)dev_get_by_id(HLD_DEV_TYPE_DMX, 0);
		ret = as_prog_pid_search(dmx, 1, priv->pid_srch_v, priv->pid_srch_a, priv->pid_srch_p);
		if(ret) //add node
		{
			MEMSET(&node,0,sizeof(node));
			node.sat_id = priv->pid_srch_tp >> NODE_ID_TP_BIT;
			node.tp_id = priv->pid_srch_tp;
			node.video_pid = priv->pid_srch_v;
			node.audio_count = 1;
			node.audio_pid[0] = priv->pid_srch_a;
			node.pcr_pid = priv->pid_srch_p;
			node.av_flag =1;
			sprintf(str,"tp%d_%d",node.tp_id,node.video_pid);
			ComAscStr2Uni(str, (UINT16*)node.service_name);
			if(SUCCESS!= lookup_node(TYPE_PROG_NODE, &node, node.tp_id))
			{
				add_node(TYPE_PROG_NODE, node.tp_id, &node);
				update_data();
			}
		}
	} 
    return ret;
}


static PRESULT win_search_update_progress(UINT8 progress_prec)
{	
	UINT8 result = PROC_LOOP;
	win_popup_choice_t popup_result=WIN_POP_CHOICE_NULL;
	UINT8 back_save;
	PROGRESS_BAR* bar;
	TEXT_FIELD* txt;
	P_NODE node;

	DBG_PRINTF("Enter %s....\n",__FUNCTION__);

	BOOL is_flash_full = FALSE;
	bar = &srch_progress_bar;
	txt = &srch_progress_txt;
	if(progress_prec == 150)
	{
		progress_prec = 100;
		is_flash_full = TRUE;
	}
	/*/*Martin@20150115_progress_bar*/
	if( progress_prec ==  6 || progress_prec ==  7 || progress_prec ==  8 || progress_prec == 10 || progress_prec == 12 || progress_prec == 21 || progress_prec == 28 ||
		progress_prec == 30 || progress_prec == 33 || progress_prec == 35 || progress_prec == 37 || progress_prec == 39 || progress_prec == 41 ||
		progress_prec == 42 || progress_prec == 44 || progress_prec == 50 || progress_prec == 54 || progress_prec == 55 || progress_prec == 57 ||
		progress_prec == 59 || progress_prec == 62 || progress_prec == 64 || progress_prec == 66 || progress_prec == 71 || progress_prec == 77 ||
		progress_prec == 79 || progress_prec == 84 || progress_prec == 86 || progress_prec == 88 || progress_prec == 91 || progress_prec == 93)
	{
		OSD_SetProgressBarPos(bar, progress_prec + 1 );
	}
	else if(progress_prec == 49 || progress_prec == 67 || progress_prec == 89 )
	{
		OSD_SetProgressBarPos(bar, progress_prec + 2 );
	}
	else
	{
	OSD_SetProgressBarPos(bar, progress_prec);
	}
	//--End Martin
	if(progress_prec< 3)
	{
		bar->wTickFg = WSTL_NOSHOW_IDX;
	}
	else
	{
		bar->wTickFg = PROGRESSBAR_PROGRESS_SH_IDX;
	}

	OSD_SetTextFieldContent(txt, STRING_NUM_PERCENT,progress_prec);
	if(priv->search_param.as_method != AS_METHOD_NIT_TP &&
		priv->search_param.as_method != AS_METHOD_NIT&&
		priv->search_param.as_method != AS_METHOD_MULTI_NIT)
	{
		OSD_DrawObject( (POBJECT_HEAD)bar, C_UPDATE_ALL);
		OSD_DrawObject( (POBJECT_HEAD)txt, C_UPDATE_ALL);
	}
    /*If search mode is AS_METHOD_NIT_TP/AS_METHOD_NIT/AS_METHOD_MULTI_NIT, do not show progress bar*/	

	if(progress_prec == 100) // is completed ?
	{
		// stop drawave timer, at first
		//osal_timer_activate(win_search_tmr_id, FALSE);
			SearchComplete = TRUE ;	
		if((priv->searched_channel_cnt[0] != 0x0)  // radio
		|| (priv->searched_channel_cnt[1] != 0x0))// tv
		{
			//win_search_save_data(TRUE);
		}
		else // not find
		{
			if(!is_flash_full)
			{
				INT32 ret = 0;
               // if(priv->search_param.as_frontend_type == FRONTEND_TYPE_S)
                 ret = do_pid_search();
			#ifdef SUPPORT_VMX
				if((!ret) && api_osm_get_confirm())
			#else
				if(!ret)
			#endif
				{
                    win_search_last_tp_ok_failed(priv->searched_tp_cnt);
					win_compopup_init(WIN_POPUP_TYPE_OK);
					win_compopup_set_msg(NULL,NULL,RS_MSG_NO_PROGRAM_FOUND);
					win_compopup_open_ext(&back_save);
				}
			}			
		}
		
		if(is_flash_full == TRUE)
		{
            win_search_last_tp_ok_failed(priv->searched_tp_cnt);
			win_compopup_init(WIN_POPUP_TYPE_OK);
			win_compopup_set_msg(NULL,NULL,RS_MSG_SPACE_FULL);
			win_compopup_open_ext(&back_save);
		}		
		result = PROC_LEAVE;
	}
	DBG_PRINTF("Exit %s....\n",__FUNCTION__);
	return result;
}


//================================search handler, run in lib_pub task ================================================
static void search_handler(UINT8 aue_type, UINT32 aue_value)
{
	union as_message msg;
	static UINT32 as_progress=0;
	UINT8 result = PROC_LOOP;
	UINT16 progress;
	UINT32 moving_disk_time;

	DBG_PRINTF("Enter %s....\n",__FUNCTION__);

	//OSD_TaskBuffer_Init(osal_task_get_current_id(),NULL);
	if (aue_type == ASM_TYPE_PROGRESS)
	{
		if (as_progress>=aue_value)
		{
			as_progress = aue_value;
			DBG_PRINTF("Exit %s....\n",__FUNCTION__);
			return;
		}
		/*
		 * without the following line will cause
		 * percentage inverse here.
		 */
		as_progress = aue_value;
	}

	msg.decode.asm_type = aue_type;
	msg.decode.asm_value = aue_value;

    switch(msg.decode.asm_type)
    {
        case ASM_TYPE_SATELLITE:
            if(priv->search_param.as_frontend_type != FRONTEND_TYPE_S)
                break;
        	osal_task_dispatch_off();
        	if(!priv->search_stop_signal)
        	{
        		priv->cur_searching_sat_no++;
        		priv->moving_disk = TRUE;
        		/* !!!!!! */
        		osal_task_dispatch_on();
        		//ap_clear_all_message();
        		ap_send_msg(CTRL_MSG_SUBTYPE_CMD_SCAN, msg.msg_encode,TRUE);
        		moving_disk_time = 0;
            }
        	else
        	{
        		osal_task_dispatch_on();
            }
            while(priv->moving_disk)
            {
        		osal_task_sleep(10);
        		moving_disk_time++ ;
            }
            as_progress = 0;
            break;
        case ASM_TYPE_PROGRESS:
            if(msg.decode.asm_value == 100 || msg.decode.asm_value == 150)
            {
                ap_send_msg(CTRL_MSG_SUBTYPE_CMD_SCAN, msg.msg_encode,TRUE);
            }
            else
            {
                if(priv->search_param.as_method != AS_METHOD_MULTI_FFT 
                    && priv->search_param.as_method != AS_METHOD_MULTI_NIT  
                    && priv->search_param.as_method != AS_METHOD_MULTI_TP)
                {
                    progress = msg.decode.asm_value;
                }
                else
                {
                    progress = (100* (priv->cur_searching_sat_no - 1)+ msg.decode.asm_value)/priv->search_param.as_sat_cnt;
                    if(progress >= 100)
                        progress = 99;
                }
                //result = win_search_update_progress(progress);//msg.decode.asm_value);
                msg.decode.asm_value = progress;
                ap_send_msg(CTRL_MSG_SUBTYPE_CMD_SCAN, msg.msg_encode,TRUE);
            }
            break;
        case ASM_TYPE_ADD_PROGRAM:
            //win_search_program_append(0xFFFFFFFF, msg.decode.asm_value);
            ap_send_msg(CTRL_MSG_SUBTYPE_CMD_SCAN, msg.msg_encode,TRUE);
            break;
        case ASM_TYPE_ADD_TRANSPONDER:
            //win_search_program_append(msg.decode.asm_value, INVALID_ID);
            ap_send_msg(CTRL_MSG_SUBTYPE_CMD_SCAN, msg.msg_encode,TRUE);
            break;
        default:
            break;
    }
	DBG_PRINTF("Exit %s....\n",__FUNCTION__);
}


//==================================window message process==================================================================
static void process_asm_type_satellite(UINT16 sat_id)
{
    S_NODE s_node;
    T_NODE t_node;
    struct ft_antenna antenna;
    union ft_xpond xpond_info;
    UINT8 back_saved;
    struct nim_device *nim = NULL;
    UINT8 cur_tunner_idx;

    MEMSET(&antenna, 0, sizeof(struct ft_antenna));
    MEMSET(&xpond_info, 0, sizeof(union ft_xpond));
    priv->cur_sat_id = sat_id;
    //get_sat_at(cur_sat_pos, VIEW_ALL,&s_node);
    get_sat_by_id(sat_id, &s_node);
    if(SUCCESS != get_tp_at(sat_id, 0, &t_node))
        MEMSET(&t_node,0,sizeof(t_node));

#ifdef DVBS_SUPPORT
    sat2antenna(&s_node, &antenna); 
#endif
    //sat2antenna_ext(&s_node, &antenna,s_node.tuner1_valid? 0 : 1);
    xpond_info.s_info.type = FRONTEND_TYPE_S;
    xpond_info.s_info.frq = t_node.frq;
    xpond_info.s_info.sym = t_node.sym;
    xpond_info.s_info.pol = t_node.pol;
    xpond_info.s_info.tp_id = t_node.tp_id;
    nim = (struct nim_device *)dev_get_by_id(HLD_DEV_TYPE_NIM, (s_node.tuner1_valid==1) ? 0 : ((s_node.tuner2_valid==1) ? 1 : 0));
    cur_tunner_idx = (s_node.tuner1_valid==1) ? 0 : ((s_node.tuner2_valid==1) ? 1 : 0);
    frontend_tuning(nim, &antenna, &xpond_info, 1);
    wincom_dish_move_popup_open(priv->pre_sat_id, sat_id, cur_tunner_idx, &back_saved);

    priv->pre_sat_id = sat_id;
    priv->moving_disk = FALSE;    
}

//Martin@20150410_ScanFrq
void draw_scan_freq_txt(UINT32 Freq)
{
	TEXT_FIELD* frq_txt;
	frq_txt = &srch_freq_value;
	char str_txt[30];
	sprintf(str_txt,": %d KHz", Freq);
	OSD_SetTextFieldContent(frq_txt, STRING_ANSI, (UINT32)str_txt);
	OSD_DrawObject( (POBJECT_HEAD)frq_txt, C_UPDATE_ALL );
}
void draw_scan_bw_txt( UINT32 Bandwidth)
{
	TEXT_FIELD* bw_txt;
	bw_txt = &srch_bw_value;
	char str_txt[30];
	sprintf(str_txt,": %d KHz", Bandwidth);
	OSD_SetTextFieldContent(bw_txt, STRING_ANSI, (UINT32)str_txt);
	OSD_DrawObject( (POBJECT_HEAD)bw_txt, C_UPDATE_ALL);
}
//----End Martin

static PRESULT	win_search_message_proc(UINT32 msg_type, UINT32 msg_code)
{
	PRESULT ret = PROC_LOOP;
	OSD_RECT rect;
	union as_message msg;	
	UINT32 posi, asm_value;

	DBG_PRINTF("Enter %s....\n",__FUNCTION__);

	switch(msg_type)
	{
	case CTRL_MSG_SUBTYPE_CMD_SCAN:
		msg.msg_encode = msg_code;
        asm_value = msg.decode.asm_value;
		switch (msg.decode.asm_type)
		{
    		case ASM_TYPE_PROGRESS:
    			ret = win_search_update_progress(asm_value);
    			break;
    		case ASM_TYPE_SATELLITE:
                if(priv->search_param.as_frontend_type == FRONTEND_TYPE_S)
                    process_asm_type_satellite((UINT16)msg.decode.asm_value);
                break;
            case ASM_TYPE_ADD_PROGRAM:
                win_search_program_append(0xFFFFFFFF, asm_value);
                break;
            case ASM_TYPE_ADD_TRANSPONDER:
                win_search_program_append(asm_value, INVALID_ID);
	#ifdef POLAND_SPEC_SUPPORT
				PostProcessing_AddNormalTP((UINT16)asm_value);
	#endif
                break;
        }



		break;
	//case CTRL_MSG_SUBTYPE_CMD_UPDATE_VIEW:
	case CTRL_MSG_SUBTYPE_CMD_TIMEDISPLAYUPDATE:
		if(as_info->xponder.t_info.frq != 0)  //Martin@20150417_ScanFrq
		{
			draw_scan_freq_txt(as_info->xponder.t_info.frq);
			draw_scan_bw_txt(as_info->xponder.t_info.band_width);
		}
		if (priv->pre_close_signal)
            break;
		//posi = msg_code;
		priv->animation_timer_loop++;
		posi = priv->animation_timer_loop % SRCH_WAVE_ICON_CNT;
		OSD_SetRect(&rect, INFO_WAV_L, INFO_WAV_T, INFO_WAV_W, INFO_WAV_H);
		win_srch_draw_bmp(&rect,srch_wave_ids[posi]);
		break;
	}
	DBG_PRINTF("Exit %s....\n",__FUNCTION__);
	return ret;
}


//==========================object key map & call back=================================================================
static void win_search_init(void)
{
    priv->pre_sat_id = 0xFFFF;
    priv->cur_sat_id = priv->search_param.sat_ids[0];

	win_search_update_progress(0);
    ap_clear_all_message();
#ifdef POLAND_SPEC_SUPPORT
	AP_InitNodeView();
#endif
	as_service_start((struct as_service_param *)&(priv->search_param));
}


static VACTION srch_keymap(POBJECT_HEAD pObj, UINT32 key)
{
	VACTION act;
	switch(key)
	{
    	case V_KEY_EXIT:
    	case V_KEY_MENU:
    		act = VACT_CLOSE;
    		break;
        case V_KEY_POWER:
            act = VACT_CLOSE;
            priv->power_off_signal = TRUE;
            break;
    	default:
    		act = VACT_PASS;
	}
	return act;	
}


static void set_win_element(BOOL open, POBJECT_HEAD pObj)
{
    UINT16 title_id = 0;
	POBJECT_HEAD mainmenu;    
    if(NULL == pObj)
        return;
    if(open)
    {
    	if(priv->search_param.as_frontend_type==FRONTEND_TYPE_S)
       {//modify for channel scan mode show the title auto scan on T tuner 2011 11 24
       //now we don't care tuner_C
       	if(priv->search_param.as_method == AS_METHOD_TP
           	  || priv->search_param.as_method == AS_METHOD_NIT_TP) // tp scan
                	title_id = RS_INSTALLATION_TP_SCAN;
        	else if(priv->search_param.as_method == AS_METHOD_FFT 
            	 || priv->search_param.as_method == AS_METHOD_MULTI_FFT)//auto scan
        	{
                #ifdef DVBS_SUPPORT
                extern UINT8  search_type ;
                if(search_type == 0)
            	 	title_id = RS_INSTALLATION_AUTO_SCAN; 
                else
                    title_id = RS_INSTALLATION_ACCURATE_SCAN;
                #else
                title_id = RS_INSTALLATION_AUTO_SCAN; 
                #endif
        	}
       	else if(priv->search_param.as_method == AS_METHOD_SAT_TP
            	 || priv->search_param.as_method == AS_METHOD_MULTI_TP
            	 || priv->search_param.as_method == AS_METHOD_NIT
            	 || priv->search_param.as_method == AS_METHOD_MULTI_NIT)//preset scan
           	 	title_id = RS_INSTALLATION_PRESET_SCAN;
       	else
           		 title_id = RS_INSTALLATION_AUTO_SCAN; 
	}
	else if(priv->search_param.as_frontend_type==FRONTEND_TYPE_T
		   ||priv->search_param.as_frontend_type==FRONTEND_TYPE_ISDBT)
		   if(is_auto_scan)
		   	title_id=RS_INSTALLATION_AUTO_SCAN;
		   else
	     		title_id = RS_INSTALLATION_CHANNEL_SCAN;  	
	
  //modify end
        wincom_open_title(pObj,title_id,0);

        /*Remove progress bar when search type is AS_METHOD_NIT_TP/AS_METHOD_NIT/AS_METHOD_MULTI_NIT*/
        if(priv->search_param.as_method == AS_METHOD_NIT_TP ||
            priv->search_param.as_method == AS_METHOD_NIT||
            priv->search_param.as_method == AS_METHOD_MULTI_NIT)
        {
            OSD_SetObjpNext(&srch_line_v,NULL);
            OSD_SetAttr(&srch_progress_txt, C_ATTR_HIDDEN);
            OSD_SetAttr(&srch_progress_bar, C_ATTR_HIDDEN);
        }
        else
        {
            OSD_SetAttr(&srch_progress_txt, C_ATTR_ACTIVE);
            OSD_SetAttr(&srch_progress_bar, C_ATTR_ACTIVE);
        }
    }
    else
    {
        OSD_ClearObject( (POBJECT_HEAD)&srch_progress_bar, C_UPDATE_ALL);
        OSD_ClearObject( (POBJECT_HEAD)&srch_progress_txt, C_UPDATE_ALL);
        if(priv->search_param.as_method == AS_METHOD_NIT_TP ||
            priv->search_param.as_method == AS_METHOD_NIT||
            priv->search_param.as_method == AS_METHOD_MULTI_NIT)
        {
            OSD_SetObjpNext(&srch_line_v,&srch_progress_bar);
        }
//modify for the title of language submenu show welcome 2011 11 24
//welcome page has been solve by other method, not use the language submenu anymore    
/*#ifdef SHOW_WELCOME_SCREEN
        if (get_win_lang_as_welcome())
        {
            OSD_ClearObject((POBJECT_HEAD)&g_win_submenu, 0);
            OSD_ClearObject((POBJECT_HEAD)&g_win_mainmenu, 0);
            wincom_close_title();
            menu_stack_pop_all();
            ap_send_msg(CTRL_MSG_SUBTYPE_CMD_ENTER_ROOT, (UINT32)&g_win_mainmenu, FALSE);
        }
        else
#endif*/
        //{
            mainmenu = (POBJECT_HEAD)&g_win_mainmenu;
            OSD_TrackObject(mainmenu,C_UPDATE_ALL);
        //}
    }
}

static void set_system_state(BOOL open)
{
    BOOL check_bypas_ci = FALSE;
#ifdef AUTOSCAN_BYPASS_CI
    check_bypas_ci = TRUE;
#endif

    if(open)
    {
        priv->power_off_signal = FALSE;
		system_state = SYS_STATE_SEARCH_PROG;
		epg_off();
		stop_tdt(); 
        
        if(check_bypas_ci && (priv->search_param.as_method == AS_METHOD_FFT ||
            priv->search_param.as_method == AS_METHOD_MULTI_FFT))
        {
            // Before Autoscan, DMX0 bypass CI
            //This can't really bypass the CI, it'll be set again in as_main
            //Normally we'll bypass the CAM when we play free channel or enter
            //menu, but some customer will modify the code, so we need to bypass
            //CAM here.
            tsi_dmx_src_select(TSI_DMX_0, TSI_TS_B);
            tsi_para_src_select(ts_route_get_nim_tsiid(0),0);
            //If we boot with CAM inserted without channel available, we'll not
            //construct the CI device list, then we can't set the bypass / pass
            //CAM with API api_set_nim_ts_type.
            //api_set_ts_pass_cam(FALSE, 3);
        }
        #ifdef CI_PLUS_SUPPORT
        //We need to bypass CAM even when we do a TP scan
        //otherwise the CAM will corrupt the TS data
        //We may find a wrong TP node information
        api_set_ts_pass_cam(FALSE, 3);
        #endif            
        #ifdef SUPPORT_CAS9                            
            #ifdef MULTI_DESCRAMBLE
            UINT8 i = 0;
            for(i = 0;i < 3;i++)  //stop filter all the TP
            {
                api_mcas_stop_transponder_multi_des(i);
            }
            #else
    			api_mcas_stop_transponder();
            #endif
        #endif
        #if defined(SUPPORT_VMX)
			UINT8 i = 0;
			for(i = 0; i < 3; i++)
			{
	        	api_mcas_stop_transponder_multi_des(i);
			}
        #endif

    }
    else
    {
        // After Autoscan, DMX0 NOT bypass CI
        if(check_bypas_ci && (priv->search_param.as_method == AS_METHOD_FFT 
            || priv->search_param.as_method == AS_METHOD_MULTI_FFT))            //auto scan
        {
            tsi_dmx_src_select(TSI_DMX_0, TSI_TS_A);
            //tsi_para_src_select(TSI_SPI_1,0);
            tsi_para_src_select(ts_route_get_nim_tsiid(0),0);
            //If no CI PLUS SUPPORT, we'll set pass / bypass CAM according
            //to channel attribute. But CI PLUS SUPPORT need we always pass
            //CAM.
            //api_set_ts_pass_cam(TRUE, 3);
        }
#ifdef CI_PLUS_SUPPORT
        api_set_ts_pass_cam(TRUE, 3);
#endif 
#ifdef SUPPORT_CAS9
        #ifdef MULTI_DESCRAMBLE
        api_mcas_start_transponder_multi_des(0);//ts_route.dmx_id-1);
        #else
	    api_mcas_start_transponder();
        #endif
#endif
#if defined(SUPPORT_VMX)
		api_mcas_start_transponder_multi_des(0);
#endif
        epg_reset();
        start_tdt();
        system_state = SYS_STATE_NORMAL;

	#if (defined(SUPPORT_VMX_STD) || defined(SUPPORT_VMX))	//resend ca system id
	#if defined(SUPPORT_VMX)
		#include <api/libcas/vmx/bc_main.h>
	#else
		#include <api/libcas/vmx_std/bc_main.h>
	#endif
		extern UINT8 g_send_ca_system_id;
		if(g_send_ca_system_id==TRUE)
		{
			VMX_API_PRINTF("%s-resend ca system id\n",__FUNCTION__);
			g_send_ca_system_id=FALSE;
			vmx_cas_sc_status_change();
		}    
    #endif
    }
}

#ifdef SUPPORT_FRANCE_HD
static void TNT_same_service_proc(UINT32 tp_id1, UINT32 tp_id2)
{
	P_NODE node;
	INT32 num1, num2, i, j;
	UINT16 *service_id, *lcn,*intensity;
	UINT8   Channel_mode;
	UINT32 MaxValidLCN =0;
	UINT16 *service_type,*hd_lcn;
	UINT16 *hd_lcn_ture,*quality;
	T_NODE tp;
	UINT16 *network_id;


	recreate_prog_view(VIEW_SINGLE_TP|PROG_TVRADIO_MODE, tp_id1);	
	num1 = get_prog_num(VIEW_ALL|PROG_TVRADIO_MODE, 0);

	service_type= (UINT16*)MALLOC(num1*2);
	hd_lcn = (UINT16*)MALLOC(num1*2);
	hd_lcn_ture=(UINT16*)MALLOC(num1*2);
	service_id = (UINT16*)MALLOC(num1*2);
	lcn = (UINT16*)MALLOC(num1*2);
	network_id= (UINT16*)MALLOC(num1*2);
	intensity=(UINT16*)MALLOC(num1*2);
	quality=(UINT16*)MALLOC(num1*2);
	
	for(i=0; i<num1; i++)
	{
		get_prog_at(i, &node);
		get_tp_by_id(node.tp_id, &tp);
		network_id[i]=tp.network_id;
		intensity[i]=tp.intensity;	
		quality[i]=tp.quality;	
		service_type[i] = node.service_type;
		hd_lcn[i] = node.hd_lcn;
		hd_lcn_ture[i] = node.hd_lcn_ture;
		service_id[i] = node.prog_number;
		lcn[i] = node.LCN;			
		DBG_PRINTF("TP %d's prog: i %d, service id %x service type = 0x%x tp.freq = %d, intensity = %d \n",\
			tp.frq, i, node.prog_number,node.service_type, tp.frq, tp.intensity);
	}

	recreate_prog_view(VIEW_SINGLE_TP|PROG_TVRADIO_MODE, tp_id2);
	num2 = get_prog_num(VIEW_ALL|PROG_TVRADIO_MODE, 0);
	 
	for(i=0; i<num1; i++)
	{
		DBG_PRINTF("\nProg %x has hd lcn, check with other...\n", service_id[i]);
		DBG_PRINTF(" service_type[%d]=%x\n", i,service_type[i]);
		if((service_type[i]==0x19)) //hd service
		{//compare program node
			if(hd_lcn_ture[i]==TRUE)//with similcast lcn
			{	
				DBG_PRINTF(" has similcast lcn \n");
				for(j=num2-1; j>=0; j--)//last
				{
					get_prog_at(j, &node);//tp2  node	
					get_tp_by_id(node.tp_id, &tp);
					//if((tp.quality<=quality[i])||(tp.intensity+5<=intensity[i]))//last <= first
					DBG_PRINTF("\n compare with prog %x\n", node.prog_number);
					DBG_PRINTF("\n prog %x 's node.hd_lcn_ture = %d, tp:frq = %d, intensity=%d; prog %x 's tp.intensity=%d\n",\
						node.prog_number,node.hd_lcn_ture, tp.frq,tp.intensity,service_id[i], intensity[i]);
					
					if((node.hd_lcn_ture==TRUE)&&(tp.intensity<=(intensity[i]+10)))//last <= first
					{
						DBG_PRINTF(" Oh, prog %x has hd_simucast_lcn, and it's signal < prog %x\n", node.prog_number, service_id[i]);
						DBG_PRINTF(" prog %x 's network_id %x, prog %x 's network_id %x \n",\
							node.prog_number, tp.network_id, service_id[i], network_id[i]);
						
						if((tp.network_id==France_HD_Network_ID)&&(network_id[i]==France_HD_Network_ID))//France network
						{	
							DBG_PRINTF("\n prog %x 's LCN %d , prog %x 's hd_simucast_lcn %d\n",\
								node.prog_number,node.LCN,service_id[i],hd_lcn[i]);
							
							if(hd_lcn[i] == node.LCN)//tp1 compare tp2
							{
								DBG_PRINTF(" Oh, them equal!So here swap\n", node.prog_number, service_id[i]);
								DBG_PRINTF(" Set prog %x's current's LCN = it's simucast LCN\n", node.prog_number);
								DBG_PRINTF(" SWAP ,LCN from %d to %d\n", node.LCN, node.hd_lcn);
								node.LCN=node.hd_lcn; // SD 
								modify_prog(node.prog_id,  &node);//sd view
								update_data();
								recreate_prog_view(VIEW_SINGLE_TP|PROG_TVRADIO_MODE, tp_id1);	
								get_prog_at(i, &node);
								DBG_PRINTF(" Set prog %x's current's LCN = it's simucast LCN\n", node.prog_number);
								DBG_PRINTF(" SWAP ,LCN from %d to %d\n", node.LCN, node.hd_lcn);
								node.LCN =hd_lcn[i] ;//HD use simukcast
								modify_prog(node.prog_id,  &node);//hd view
								update_data();
								recreate_prog_view(VIEW_SINGLE_TP|PROG_TVRADIO_MODE, tp_id2);	
							}						
						}
						else
						{
								if(tp.network_id!=France_HD_Network_ID)
								{
									if (node.LCN<800 )
									{
										node.LCN =  find_dtg_variant_region_LCN();
										DBG_PRINTF(" Foreign ! tp.network_id=%x lcn %d\n", tp.network_id,node.LCN);
										modify_prog(node.prog_id,  &node);	
										update_data();
									}
								}
								else if(network_id[i]!=France_HD_Network_ID)
								{
									
									recreate_prog_view(VIEW_SINGLE_TP|PROG_TVRADIO_MODE, tp_id1);	
									get_prog_at(i, &node);
									if (node.LCN<800 )
									{
										node.LCN =  find_dtg_variant_region_LCN();	
										DBG_PRINTF(" Foreign ! network_id[%d]=%x lcn %d\n",i,network_id[i],node.LCN);
										modify_prog(node.prog_id,  &node);	
										update_data();
										recreate_prog_view(VIEW_SINGLE_TP|PROG_TVRADIO_MODE, tp_id2);	
									}
								}
						}
					}
				}
			}
		}
	}

	FREE(service_id);
	FREE(lcn);
	FREE(hd_lcn);
	FREE(hd_lcn_ture);
	FREE(service_type);
	FREE(network_id);
	FREE(intensity);
	FREE(quality);
}

static void TNT_search_TS_proc(UINT16 sat_id)
{
	INT32 i, j, k, t_num;
	UINT16 network_id, ts_id,intensity=0;
	UINT32 tp_id;
	T_NODE t_node;
	UINT8   Channel_mode, db_changed = 0,quality=0;	

	//reserve status
    	Channel_mode = sys_data_get_cur_chan_mode();

	t_num = get_tp_num_sat(sat_id);

	DBG_PRINTF("Let's Check all program's LCN:\n");
	DBG_PRINTF("\tCurrent DB has %d TPs\n", t_num);
	//compare all tp node
	for(j=0; j<t_num; j++)
	{
		get_tp_at(sat_id, j, &t_node);

		network_id = t_node.network_id;
		ts_id = t_node.t_s_id;
        tp_id = t_node.tp_id;
		DBG_PRINTF("\nCurrently check the [%d] tp with others...tp id = %d, ts id = %d freq = %d\n", j, tp_id, ts_id, t_node.frq);
		for(k=t_num-1; k>=0; k--)
		{
			if (k==j)
				continue;
			get_tp_at(sat_id, k, &t_node);
			DBG_PRINTF("\nCompare with [%d] tp tp id = %d ts id = %d  ", k, t_node.tp_id, t_node.t_s_id);
			DBG_PRINTF("freq %d intensity %d, quality %d\n",t_node.frq,t_node.intensity,t_node.quality );
			TNT_same_service_proc(tp_id,t_node.tp_id);								
			update_data();
		}			
			
	  }

}
#endif
static PRESULT srch_callback(POBJECT_HEAD pObj, VEVENT event, UINT32 param1, UINT32 param2)
{
	PRESULT ret = PROC_PASS;
	UINT8 av_flag;
	UINT16 cur_chan;
	UINT32 position=0;
	UINT8 back_saved;
	POBJECT_HEAD mainmenu;//modify for adding welcome page when only open dvbt2011 10 17
	UINT16 title_id;//modify for adding welcome page when only open dvbt 2011 10 17
	#ifdef NIM_S3501_ASCAN_TOOLS
	UINT32 tmp_val=0x00,i;
	char hint[130];
	#endif
	
	switch(event)
	{
	case EVN_PRE_OPEN:
        ASSERT(NULL != priv);
        set_win_element(TRUE, pObj);
        set_system_state(TRUE);  
        MEMSET((void*)(display_strs[30]), 0, MAX_DISP_STR_LEN*2*INFOR_TP_CNT);
 		key_pan_display("srch", 4);
		SearchComplete = FALSE;
		break;
	case EVN_POST_OPEN:
		win_search_init();
		break;        
	case EVN_PRE_CLOSE:
        priv->pre_close_signal = TRUE;
		osal_task_dispatch_off();
        priv->moving_disk = FALSE;/*Clear moving dish flag*/
        priv->search_stop_signal = TRUE;
        priv->pid_srch_flag = FALSE;
		osal_task_dispatch_on();
		as_service_stop();
		db_search_exit();
		//api_stop_timer(&win_search_tmr_id);
		/* Make OSD not flickering */
		*((UINT32*)param2) &= ~C_CLOSE_CLRBACK_FLG;			
		prog_callback_unregister();
	
		
		break;
       
	case EVN_POST_CLOSE:
		if((priv->searched_channel_cnt[0] != 0x0)
			|| (priv->searched_channel_cnt[1] != 0x0))
		{
#ifdef POLAND_SPEC_SUPPORT
		if(SearchComplete == TRUE || AutoScanUpdateMode() == FALSE)
			PostUpdateProgram();
#endif	
            win_search_last_tp_ok_failed(priv->searched_tp_cnt);

			win_compopup_init(WIN_POPUP_TYPE_SMSG);
			win_compopup_set_msg(NULL, NULL, RS_MSG_WAIT_FOR_SAVING);
			//win_compopup_open();
			win_compopup_open_ext(&back_saved);
#ifdef _INVW_JUICE   
			osal_delay_ms(1000);
			INVIEW_UpdateDatabase(); //v0.1.4
#endif
			#if(defined(SUPPORT_FRANCE_HD))
				TNT_search_TS_proc(1);
			#endif
			update_data();
		#ifdef SUPPORT_VMX
			if((!priv->power_off_signal) && api_osm_get_confirm())
		#else
            if(!priv->power_off_signal)
		#endif
            {
                win_compopup_smsg_restoreback();  				    
		    	win_compopup_init(WIN_POPUP_TYPE_OK);
		    	win_compopup_set_msg("Search End", NULL, 0);
		    	win_compopup_open_ext(&back_saved);
            }
            recreate_prog_view(VIEW_ALL | PROG_TVRADIO_MODE ,0);
			reset_group();
            UINT32 grp_idx = sys_data_get_cur_group_index();
			sys_data_check_channel_groups();
			sys_data_set_cur_group_index(grp_idx);

			av_flag = sys_data_get_cur_chan_mode();
			if(sys_data_get_sate_group_num(av_flag) == 0)
			{
				av_flag = (av_flag == TV_CHAN)? RADIO_CHAN : TV_CHAN;
				sys_data_set_cur_chan_mode(av_flag);
			}
			sys_data_change_group(grp_idx);
#ifdef _LCN_ENABLE_
		//recreate_prog_view(VIEW_ALL | PROG_TVRADIO_MODE ,0);//modify for adding welcome page when only open dvbt 2011 10 17
            if(sys_data_get_LCN())
			{
                sort_prog_node(PROG_LCN_SORT);
//            else           
//                sort_prog_node(PROG_DEFAULT_SORT);
	            update_data();
			}
#endif
			
			UINT8 av_other =  (av_flag == TV_CHAN)? RADIO_CHAN : TV_CHAN; 
			if(priv->searched_channel_cnt[av_flag] > 0)
			{
#if 1//ChengYu@20130927, play the first program after scan
				priv->cur_searched_prog[av_flag].prog_id = srch_first_prog_id[av_flag];
#endif
#ifdef POLAND_SPEC_SUPPORT
			position=get_prog_id_indb(&(priv->cur_searched_prog[av_flag]));
		
			if(position== 0)
			
		cur_chan=get_prog_num(VIEW_ALL|av_flag,0)-1;
			
		else
			cur_chan = get_prog_pos(position);
#else
			cur_chan = get_prog_pos(priv->cur_searched_prog[av_flag].prog_id);
#endif
				if(cur_chan == 0xFFFF)
				{
                    grp_idx = get_sat_pos(priv->cur_sat_id) + 1;
        			sys_data_change_group(grp_idx);
    				cur_chan = get_prog_pos(priv->cur_searched_prog[av_flag].prog_id);
                    if (cur_chan == 0xFFFF)
                    {
            			sys_data_change_group(0);
        				cur_chan = get_prog_pos(priv->cur_searched_prog[av_flag].prog_id);
                        if (cur_chan == 0xffff)
    					    cur_chan = 0;
                    }
				}
				sys_data_set_cur_group_channel(cur_chan);
			}
			else if(priv->searched_channel_cnt[av_other] > 0)
			{
				sys_data_set_cur_chan_mode(av_other);	
				reset_group();				
#ifdef POLAND_SPEC_SUPPORT
				position=get_prog_id_indb(&(priv->cur_searched_prog[av_other]));
				if(position== 0)
				cur_chan=get_prog_num(VIEW_ALL|av_other,0)-1;
				else
				cur_chan = get_prog_pos(position);
#else
				cur_chan = get_prog_pos(priv->cur_searched_prog[av_other].prog_id);
#endif
				if(cur_chan == 0xFFFF)
				{
                    grp_idx = get_sat_pos(priv->cur_sat_id) + 1;
        			sys_data_change_group(grp_idx);
    				cur_chan = get_prog_pos(priv->cur_searched_prog[av_other].prog_id);
                    if (cur_chan == 0xFFFF)
                    {
            			sys_data_change_group(0);
        				cur_chan = get_prog_pos(priv->cur_searched_prog[av_other].prog_id);
                        if (cur_chan == 0xffff)
    					    cur_chan = 0;
                    }
				}
				sys_data_set_cur_group_channel(cur_chan);
			}
			else if(sys_data_get_sate_group_num(av_flag))
				key_pan_display("noCH", 4);
			else
				key_pan_display("----", 4);
			sys_data_save(1);
	
	    }

	#ifdef NIM_S3501_ASCAN_TOOLS
				extern UINT32 nim_s3501_ascan_get_loop_cnt();
				extern UINT32 nim_s3501_ascan_get_time(UINT32 idx);
				extern UINT32 nim_s3501_ascan_get_tps(UINT32 idx);
				tmp_val=nim_s3501_ascan_get_loop_cnt();
				memset(hint,0,sizeof(char)*130);
				sprintf(hint, "Search times:%d\n",tmp_val);
				tmp_val = tmp_val>5? 5:tmp_val;
				for(i=0;i<tmp_val;i++)
				{
					sprintf(hint+strlen(hint), "T:%d,TPs:%d;",nim_s3501_ascan_get_time(i),nim_s3501_ascan_get_tps(i));
				}
				win_compopup_set_msg(hint, NULL, 0);
				win_compopup_open_ext(&back_saved);
	    #endif
        set_win_element(FALSE, pObj);
        set_system_state(FALSE); 
#ifdef SHOW_WELCOME_FIRST		
	    //modify for adding welcome page when only open dvbt2011 10 17
	 if(!priv->power_off_signal)
	  {
		OSD_ClearObject( (POBJECT_HEAD)&srch_progress_bar, C_UPDATE_ALL);
		OSD_ClearObject( (POBJECT_HEAD)&srch_progress_txt, C_UPDATE_ALL);
		if(win_search_param.as_method == AS_METHOD_NIT_TP ||
			win_search_param.as_method == AS_METHOD_NIT||
			win_search_param.as_method == AS_METHOD_MULTI_NIT)
		{
            OSD_SetObjpNext(&srch_line_v,&srch_progress_bar);
		}
		mainmenu = (POBJECT_HEAD)&g_win_mainmenu;
		OSD_TrackObject(mainmenu,C_UPDATE_ALL);
		//modify end
		//modify for adding welcome page when only open dvbt 2011 19 18		
        start_tdt();
		system_state = SYS_STATE_NORMAL;
        
		// Gavim@20141230_autoscan ~ if channel exist always play channel after scan 
		//	if(g_enter_welcom==1)

		{
			if((priv->searched_channel_cnt[0] != 0x0)
			|| (priv->searched_channel_cnt[1] != 0x0))
			{	
				OSD_ClearObject((POBJECT_HEAD)&g_win_submenu, 0);
				OSD_ClearObject((POBJECT_HEAD)&g_win_mainmenu, 0);
				wincom_close_title();
				menu_stack_pop_all();
				UINT16 channel = sys_data_get_cur_group_cur_mode_channel();
 
				api_play_channel(channel, TRUE, TRUE,FALSE);	
				ap_send_msg(CTRL_MSG_SUBTYPE_CMD_ENTER_ROOT, (POBJECT_HEAD)&g_win_progname, FALSE);
#if 1//ChengYu@20140217, factory mode implement
				if (Factory_Mode_Get_Flag()==TRUE)
					set_factory_scan_result(TRUE);
#endif
			}else
			{
				OSD_ClearObject((POBJECT_HEAD)&g_win_submenu, 0);
				OSD_ClearObject((POBJECT_HEAD)&g_win_mainmenu, 0);
				wincom_close_title();
				menu_stack_pop_all();
#if 1//ChengYu@20140217, factory mode implement
				if (Factory_Mode_Get_Flag()==TRUE)
			{	
					set_factory_scan_result(FALSE); //no program found
					api_stop_play(0);
					ap_send_msg(CTRL_MSG_SUBTYPE_CMD_ENTER_ROOT, (UINT32)&g_win_factory_test, FALSE);
			}
			else
				ap_send_msg(CTRL_MSG_SUBTYPE_CMD_ENTER_ROOT, (UINT32)&g_win_mainmenu, FALSE);
#endif
			}
			break;
		}
#ifdef SUPPORT_FRANCE_HD		
		else if(g_enter_welcom==2)
		{
				OSD_ClearScreen();
				menu_stack_pop_all();
				UINT16 channel = sys_data_get_cur_group_cur_mode_channel();
				api_play_channel(channel, TRUE, TRUE,FALSE);	
				ap_send_msg(CTRL_MSG_SUBTYPE_CMD_ENTER_ROOT, (POBJECT_HEAD)&g_win_progname, FALSE);
		}
#endif		

#ifdef POLAND_SPEC_SUPPORT
		else if(g_enter_welcom==3)
		{
			if((priv->searched_channel_cnt[0] != 0x0)
			|| (priv->searched_channel_cnt[1] != 0x0))
			{	
				OSD_ClearObject((POBJECT_HEAD)&g_win_submenu, 0);
				OSD_ClearObject((POBJECT_HEAD)&g_win_mainmenu, 0);
				wincom_close_title();
				menu_stack_pop_all();
				UINT16 channel = sys_data_get_cur_group_cur_mode_channel();
 
				api_play_channel(channel, TRUE, TRUE,FALSE);	
				ap_send_msg(CTRL_MSG_SUBTYPE_CMD_ENTER_ROOT, (POBJECT_HEAD)&g_win_progname, FALSE);
				
			}
			else
			{
				OSD_ClearObject((POBJECT_HEAD)&g_win_submenu, 0);
				OSD_ClearObject((POBJECT_HEAD)&g_win_mainmenu, 0);
				wincom_close_title();
				menu_stack_pop_all();
				ap_send_msg(CTRL_MSG_SUBTYPE_CMD_ENTER_ROOT, (UINT32)&g_win_mainmenu, FALSE);
			}
			g_enter_welcom = 0;
			break;
		}
#endif

		}		
		//modify end
#endif	
#ifdef POLAND_SPEC_SUPPORT
				AP_FreeNodeView();  // free node view
#endif
		SearchComplete = FALSE;
		SetAutoScanUpdateMode(FALSE);
        if(priv->power_off_signal)
			power_switch(0);
        FREE(priv);
        priv = NULL;
		break;
	case EVN_MSG_GOT:
		ret = win_search_message_proc(param1,param2);		
		break;
	}
	return ret;
}

static PRESULT srch_backtxt_callback(POBJECT_HEAD pObj, VEVENT event, UINT32 param1, UINT32 param2)
{
    INT i;
	PRESULT ret = PROC_PASS;	
	UINT8 bID = OSD_GetObjID(pObj);
	OSD_RECT rect;
    TEXT_FIELD *pTxt;
	switch(event)
	{
	case EVN_POST_DRAW:        
		if(bID == TVB_ID)
		{
			OSD_SetRect(&rect, TVB_L + 18, TVB_T,36,36);//, 20, 20);
			//win_srch_draw_bmp(&rect,IM_ORANGE_ARROW_MAINMENU);
			win_srch_draw_bmp(&rect,IM_GROUP_RIGHT);

            rect.uLeft 	= TVB_L +20;
    		rect.uTop  	= TVB_T;
    		rect.uWidth = TXT_W;
    		rect.uHeight= TXT_W;
            pTxt = &srch_info_txt_ex;
            OSD_SetColor(pTxt,WIN_CON_NOSHOW,WIN_CON_NOSHOW,WIN_CON_NOSHOW,WIN_CON_NOSHOW);
    		for(i = 0; i < INFOR_CHAN_CNT + 1;i++)
    		{
                win_srch_draw_info_ex(&rect,"",(UINT16 *)NULL,0);
                rect.uTop+=TXT_H + LINE_H;
            }
            OSD_SetColor(pTxt,RADIO_TXT_SH_IDX,RADIO_TXT_SH_IDX,RADIO_TXT_SH_IDX,RADIO_TXT_SH_IDX);          
		}
		else if(bID == RADIOB_ID)
		{
			OSD_SetRect(&rect, RADIOB_L + 18, RADIOB_T,36,36);//, 20, 20);
			//win_srch_draw_bmp(&rect,IM_ORANGE_ARROW_MAINMENU);
			win_srch_draw_bmp(&rect,IM_GROUP_RIGHT);

            rect.uLeft 	= RADIOB_L+20;
    		rect.uTop  	= RADIOB_T;            
        	rect.uWidth = TXT_W;
        	rect.uHeight= TXT_W;
            pTxt = &srch_info_txt_ex;
            OSD_SetColor(pTxt,WIN_CON_NOSHOW,WIN_CON_NOSHOW,WIN_CON_NOSHOW,WIN_CON_NOSHOW);
    		for(i = 0; i < INFOR_CHAN_CNT + 1;i++)
    		{
                win_srch_draw_info_ex(&rect,"",(UINT16 *)NULL,0);
                rect.uTop+=TXT_H + LINE_H;
            }
            OSD_SetColor(pTxt,RADIO_TXT_SH_IDX,RADIO_TXT_SH_IDX,RADIO_TXT_SH_IDX,RADIO_TXT_SH_IDX);
            
		}
		else if(bID == TPB_ID)
		{
			OSD_SetRect(&rect, INFO_SAT_L, INFO_SAT_T, INFO_SAT_W, INFO_SAT_H);
			//win_srch_draw_bmp(&rect,IM_SATELLITE);
            win_srch_draw_bmp(&rect,IM_SATELLITE);    
			OSD_SetRect(&rect, INFO_RCV_L, INFO_RCV_T, INFO_RCV_W, INFO_RCV_H);
			//win_srch_draw_bmp(&rect,IM_RECEIVE);
            win_srch_draw_bmp(&rect,IM_RECEIVE);
		}
		//win_srch_draw_info_ex(&rect, NULL,pstr, INFOMATION_TXT_IDX)
        break;
	}
	return ret;
}


//=============================Public API===============================================================================
void win_search_set_param(struct as_service_param * param)
{
	ASSERT(param != NULL);
    if(NULL == priv)
    {
        priv = (WinSrchPriv*)MALLOC(sizeof(WinSrchPriv));
        if(NULL != priv)
        {
            MEMSET((void*)priv, 0, sizeof(WinSrchPriv));
            MEMCPY(&priv->search_param, param, sizeof(struct as_service_param));
            priv->search_param.as_handler = search_handler;
        }
	    else
            DBG_PRINTF("error: malloc filed at fun: %s line: %d\n", __FUNCTION__, __LINE__);
    }
    else
    {
	MEMSET((void*)priv, 0, sizeof(WinSrchPriv));
        MEMCPY(&priv->search_param, param, sizeof(struct as_service_param));
        priv->search_param.as_handler = search_handler;
    }
}

//add on 2011-11-04 
//#if (SYS_PROJECT_FE == PROJECT_FE_DVBC)
#ifdef DVBC_SUPPORT
//for test

void win_search_set_autoscan_param(void)
{
	struct as_service_param param;
	struct vdec_device *vdec;
	struct vdec_io_get_frm_para vfrm_param;
	SYSTEM_DATA*	sys_data;
	UINT8 uBandCnt,index_BandCnt,i;
	UINT32  search_mode, prog_type;
	UINT32 addr, len;


	sys_data = sys_data_get();
    #if defined(_S3281_) && defined(DVBC_SUPPORT)
    if(sys_data->dvbc_mode == 0)
    {
	    get_default_bandparam(sys_data->country, (Band_param *)&uCountryParam);
    }
    else
    {
        MEMSET(&uCountryParam,0,sizeof(uCountryParam));
	    get_default_bandparam_QAMB(sys_data->country, (Band_param *)&uCountryParam);
    }
    #else
    get_default_bandparam(sys_data->country, (Band_param *)&uCountryParam);
    #endif  
    
	uBandCnt = 0;
	for(index_BandCnt=0;index_BandCnt<MAX_BAND_COUNT;index_BandCnt++)
	{
		if(uCountryParam[index_BandCnt].start_freq==0)//warning shooting xing
			break;
		else
			uBandCnt++;
	}

	MEMSET(&param, 0, sizeof(struct as_service_param));

	prog_type = P_SEARCH_TV | P_SEARCH_RADIO;
	search_mode = P_SEARCH_FTA | P_SEARCH_SCRAMBLED;
	param.as_prog_attr = prog_type|search_mode;
	param.as_frontend_type = FRONTEND_TYPE_C;
	param.sat_ids[0] = 1;
	param.as_sat_cnt = 1;
	param.as_method = AS_METHOD_FFT;
	param.as_p_add_cfg = PROG_ADD_REPLACE_OLD;
	param.as_handler = NULL;
	param.band_group_param=uCountryParam;
	param.scan_cnt = uBandCnt;


    for(i=0;i<sys_data->current_ft_count;i++)
    {
        param.ft[i].c_param.sym = sys_data->current_ft[i].c_param.sym;
        param.ft[i].c_param.constellation = sys_data->current_ft[i].c_param.constellation;
    }

    param.ft_count = sys_data->current_ft_count;


    //libc_printf("param.ft_count:%d\n",param.ft_count);
   //libc_printf("param.ft[0].c_param.sym:%d constellation: %d\n",param.ft[0].c_param.sym, param.ft[0].c_param.constellation);
   // libc_printf("param.ft[1].c_param.sym:%d constellation: %d\n",param.ft[1].c_param.sym, param.ft[1].c_param.constellation);


	win_search_set_param(&param);

	vdec = (struct vdec_device *)dev_get_by_id(HLD_DEV_TYPE_DECV, 0);
	vfrm_param.ufrm_mode = VDEC_UN_DISPLAY;
	vdec_io_control(vdec, VDEC_IO_GET_FRM, (UINT32)&vfrm_param);
	addr = vfrm_param.tFrmInfo.uY_Addr;
	len = (vfrm_param.tFrmInfo.uHeight * vfrm_param.tFrmInfo.uWidth * 3) / 2;

	db_search_init((UINT8 *)addr, len);

}
#endif


void win_search_set_pid_param(UINT32 tp,UINT32 VPid,UINT32 APid,UINT32 PPid)
{
    if(NULL == priv)
    {
        priv = (WinSrchPriv*)MALLOC(sizeof(WinSrchPriv));
        if(NULL != priv)
        {
            MEMSET((void*)priv, 0, sizeof(WinSrchPriv));
            priv->pid_srch_flag = TRUE;
            priv->pid_srch_tp = tp;
            priv->pid_srch_a = APid;
            priv->pid_srch_v = VPid;
            priv->pid_srch_p = PPid;
        }
        else
            DBG_PRINTF("error: malloc filed at fun: %s line: %d\n", __FUNCTION__, __LINE__);
    }
    else
    {
        priv->pid_srch_flag = TRUE;
        priv->pid_srch_tp = tp;
        priv->pid_srch_a = APid;
        priv->pid_srch_v = VPid;
        priv->pid_srch_p = PPid;        
    }
}

//------------------------------for CI -----------------------------------------------------------
static UINT8 ci_cur_slot = -1;
static void ci_search_handler(UINT8 aue_type, UINT32 aue_value)
{
    UINT32 msg_code = ci_cur_slot << 16;
    
    if ((aue_type == ASM_TYPE_PROGRESS) && (aue_value == 100 || aue_value == 150))
    {
        // Send message to control task to played found channel
        msg_code |= API_MSG_TUNED_SEARCH_END;
        ap_send_msg(CTRL_MSG_SUBTYPE_STATUS_CI, msg_code, FALSE);        
    }
    search_handler(aue_type, aue_value);
}

void ci_camup_search_set_param(struct as_service_param * param, UINT8 slot)
{
	ASSERT(param != NULL);
    ci_cur_slot = slot;
    if(NULL == priv)
    {
        priv = (WinSrchPriv*)MALLOC(sizeof(WinSrchPriv));
        if(NULL != priv)
        {
            MEMSET((void*)priv, 0, sizeof(WinSrchPriv));
  	        MEMCPY(&priv->search_param, param, sizeof(struct as_service_param));
	        priv->search_param.as_handler = ci_search_handler;          
        }
    }
    else
    {
        MEMCPY(&priv->search_param, param, sizeof(struct as_service_param));
        priv->search_param.as_handler = ci_search_handler;     
    }
}


#if 1//ChengYu@20140217, factory mode implement
void scanchannel(UINT32 frequency, UINT32 bandwidth )
{
    POBJECT_HEAD top_win, win_menu;
    top_win =  menu_stack_get_top();
    struct as_service_param param;
    UINT32 addr,len;
	T_NODE t_node;
	INT32 ret;
    UINT16 sat_id;

    if( top_win != NULL )
    {
		api_osd_mode_change(OSD_NO_SHOW);
        ap_clear_all_menus();//clear all menu & Hidden osd show
        menu_stack_pop_all();
    }

	//Search channel by frequency
	//===================================
	MEMSET(&param, 0, sizeof(struct as_service_param));
	MEMSET(&t_node, 0, sizeof(T_NODE));

    sat_id = get_frontend_satid(FRONTEND_TYPE_T, 0);

	t_node.sat_id = sat_id;
	t_node.ft_type = FRONTEND_TYPE_T;
	t_node.frq = frequency;
	t_node.bandwidth = bandwidth/1000;
	t_node.band_type = 1;

	recreate_tp_view(VIEW_SINGLE_SAT, 1);
	ret = lookup_node(TYPE_TP_NODE, &t_node, t_node.sat_id);
	if (ret != SUCCESS)
	{
		add_node(TYPE_TP_NODE, t_node.sat_id, &t_node);
		update_data();
		libc_printf("add a new node\n");
	}
	param.as_prog_attr = P_SEARCH_ALL;
	param.as_p_add_cfg = PROG_ADD_REPLACE_OLD;
	param.as_method = AS_METHOD_FREQ_BW;
	param.as_frontend_type = FRONTEND_TYPE_T;
	param.as_sat_cnt = 1;
	param.sat_ids[0] = sat_id;
	param.as_handler = NULL;
	param.as_from = t_node.tp_id;
	param.as_to = 0;
	win_search_set_param(&param);

	update_data();

	addr = __MM_AUTOSCAN_DB_BUFFER_ADDR;
	addr &= 0x8fffffff;
	len = __MM_AUTOSCAN_DB_BUFFER_LEN;

	db_search_init((UINT8 *)addr, len);
	//===================================

	api_show_menu_logo();
    win_menu = (POBJECT_HEAD)&g_win_search;
    ap_send_msg(CTRL_MSG_SUBTYPE_CMD_ENTER_ROOT,(UINT32)win_menu, FALSE);
}
#endif

